﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_chucdanhInfo
    {
        private string _machucdanh;
        private string _tenchucdanh;
        private string _ghichu;
        private int _thutu;
        private bool _chucdanhnhom;
        private bool _lanh_dao;
        private string _ngaynhap;
        private int _nguoinhap;
        private string _ngaysua;
        private int _nguoisua;
        private int _nghiphep;

        public cs_hmr_chucdanhInfo()
        {
            this._machucdanh = " ";
            this._tenchucdanh = " ";
            this._ghichu = " ";
            this._thutu = 0;
            this._chucdanhnhom = true;
            this._lanh_dao = true;
            this._ngaynhap = " ";
            this._nguoinhap = 0;
            this._ngaysua = " ";
            this._nguoisua = 0;
            this._nghiphep = 0;

        }
        public string machucdanh
        {
            get
            {
                return this._machucdanh;
            }
            set
            {
                this._machucdanh = value;
            }
        }
        public string tenchucdanh
        {
            get
            {
                return this._tenchucdanh;
            }
            set
            {
                this._tenchucdanh = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }
        public int thutu
        {
            get
            {
                return this._thutu;
            }
            set
            {
                this._thutu = value;
            }
        }
        public bool chucdanhnhom
        {
            get
            {
                return this._chucdanhnhom;
            }
            set
            {
                this._chucdanhnhom = value;
            }
        }
        public bool lanh_dao
        {
            get
            {
                return this._lanh_dao;
            }
            set
            {
                this._lanh_dao = value;
            }
        }
        public string ngaynhap
        {
            get
            {
                return this._ngaynhap;
            }
            set
            {
                this._ngaynhap = value;
            }
        }
        public int nguoinhap
        {
            get
            {
                return this._nguoinhap;
            }
            set
            {
                this._nguoinhap = value;
            }
        }
        public string ngaysua
        {
            get
            {
                return this._ngaysua;
            }
            set
            {
                this._ngaysua = value;
            }
        }
        public int nguoisua
        {
            get
            {
                return this._nguoisua;
            }
            set
            {
                this._nguoisua = value;
            }
        }
        public int nghiphep
        {
            get
            {
                return this._nghiphep;
            }
            set
            {
                this._nghiphep = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[12];
            paraName[0] = "@machucdanh";
            paraName[1] = "@tenchucdanh";
            paraName[2] = "@ghichu";
            paraName[3] = "@thutu";
            paraName[4] = "@chucdanhnhom";
            paraName[5] = "@lanh_dao";
            paraName[6] = "@ngaynhap";
            paraName[7] = "@nguoinhap";
            paraName[8] = "@ngaysua";
            paraName[9] = "@nguoisua";
            paraName[10] = "@nghiphep";
            paraName[11] = "@option";
            object[] paraValue = new object[12];
            paraValue[0] = this._machucdanh;
            paraValue[1] = this._tenchucdanh;
            paraValue[2] = this._ghichu;
            paraValue[3] = this._thutu;
            paraValue[4] = this._chucdanhnhom;
            paraValue[5] = this._lanh_dao;
            paraValue[6] = this._ngaynhap;
            paraValue[7] = this._nguoinhap;
            paraValue[8] = this._ngaysua;
            paraValue[9] = this._nguoisua;
            paraValue[10] = this._nghiphep;
            paraValue[11] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 12, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[11];
            fields[0] = "machucdanh";
            fields[1] = "tenchucdanh";
            fields[2] = "ghichu";
            fields[3] = "thutu";
            fields[4] = "chucdanhnhom";
            fields[5] = "lanh_dao";
            fields[6] = "ngaynhap";
            fields[7] = "nguoinhap";
            fields[8] = "ngaysua";
            fields[9] = "nguoisua";
            fields[10] = "nghiphep";
            list.KetDulieu(myList, "HMR_CHUCDANH", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_CHUCDANH", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("tenchucdanh", "machucdanh");
            cb.KetDuLieu(cbo, "HMR_CHUCDANH", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[11];
            header[0] = "machucdanh";
            header[1] = "tenchucdanh";
            header[2] = "ghichu";
            header[3] = "thutu";
            header[4] = "chucdanhnhom";
            header[5] = "lanh_dao";
            header[6] = "ngaynhap";
            header[7] = "nguoinhap";
            header[8] = "ngaysua";
            header[9] = "nguoisua";
            header[10] = "nghiphep";

            string[] mappingname = new string[11];
            mappingname[0] = "machucdanh";
            mappingname[1] = "tenchucdanh";
            mappingname[2] = "ghichu";
            mappingname[3] = "thutu";
            mappingname[4] = "chucdanhnhom";
            mappingname[5] = "lanh_dao";
            mappingname[6] = "ngaynhap";
            mappingname[7] = "nguoinhap";
            mappingname[8] = "ngaysua";
            mappingname[9] = "nguoisua";
            mappingname[10] = "nghiphep";

            int[] colwidth = new int[11];
            colwidth[0] = 30;
            colwidth[1] = 300;
            colwidth[2] = 300;
            colwidth[3] = 12;
            colwidth[4] = 3;
            colwidth[5] = 3;
            colwidth[6] = 90;
            colwidth[7] = 12;
            colwidth[8] = 90;
            colwidth[9] = 12;
            colwidth[10] = 12;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_CHUCDANH", datagrid, csdl.OpenTable("HMR_CHUCDANH", condition), header, mappingname, colwidth, 11);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_CHUCDANH", "machucdanh = '" + this._machucdanh + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._machucdanh = ds.Tables[0].Rows[0]["machucdanh"].ToString().Trim();
                this._tenchucdanh = ds.Tables[0].Rows[0]["tenchucdanh"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._thutu = Convert.ToInt32(ds.Tables[0].Rows[0]["thutu"].ToString().Trim());
                this._chucdanhnhom = Convert.ToBoolean(ds.Tables[0].Rows[0]["chucdanhnhom"].ToString().Trim());
                this._lanh_dao = Convert.ToBoolean(ds.Tables[0].Rows[0]["lanh_dao"].ToString().Trim());
                this._ngaynhap = ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim();
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._ngaysua = ds.Tables[0].Rows[0]["ngaysua"].ToString().Trim();
                this._nguoisua = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoisua"].ToString().Trim());
                this._nghiphep = Convert.ToInt32(ds.Tables[0].Rows[0]["nghiphep"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select rtrim(machucdanh) as machucdanh, rtrim(tenchucdanh) as tenchucdanh, rtrim(ghichu) as ghichu "
                        + " from HMR_CHUCDANH";
                ds = csdl.SelecSQL(sql);
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
